<?php
class helper_setting extends system_view_helper_abstract {
	
	private $_dirname = 'setting';
	private $_data = array();
	private $_module = null;
	/**
	 * @return helper_setting
	 */
	public function setting($module = 'system') {
		$this->_module = strtolower($module);	
		if(!isset($this->_data[$this->_module])) {
			$dir = _DIRECTORY_VAR . DIRECTORY_SEPARATOR . 'cache' . DIRECTORY_SEPARATOR . $this->_dirname;
			$cache = system_cache::factory($this->_dirname, array('dir' => $dir));
			$this->_data[$this->_module] = $cache->load($this->_module);
					
			if(!$this->_data[$this->_module]) {
				$this->_data[$this->_module] = system_setting_concept::queryCacheList($this->_module);
				$cache->save($this->_module, $this->_data[$this->_module]);
			}
		}
		return $this;
	}
	
	public function __call($method, array $args) {
		if(preg_match('/^get(\w+?)$/', $method, $matches)) {
			return $this->get($matches[1], '');
		}
		return null;
	}
	
	public function get($name, $defValue = null) {
		$name = strtolower($name);
		if(!isset($this->_data[$this->_module])) return $defValue;
		if(!isset($this->_data[$this->_module][$name])) return $defValue;
		return $this->_data[$this->_module][$name];
	}

}